﻿using System;

namespace MVVMS
{
    public delegate void NotificationEventHandler<NotificationEventArg>(object sender, NotificationEventArg e);

    public static class Notifications
    {
        /// <summary>
        /// BEST PRACTICE: Use the provided WeakEventHandler class to consume this event.
        /// Example: 
        ///     ReceiveNotification += WeakEventHandler<NotificationEventArg>( (nea) => 
        ///         { 
        ///             // Place Implementation Here
        ///         } ).Handler;
        /// </summary>
        public static event NotificationEventHandler<NotificationEventArg> ReceiveNotification;

        /// <summary>
        /// Sends a Message for others to Receive
        /// </summary>
        /// <param name="sender">Who Sent the message</param>
        /// <param name="Message">What is the message?</param>
        /// <param name="Value">Is there an associated value?</param>
        /// <param name="Callback">Callback (may be called many times or not at all)</param>
        public static void SendNotification(object sender, string Message, object Value, Action Callback)
        {

            // Raise the Notification
            if (ReceiveNotification != null)
                ReceiveNotification(sender, new NotificationEventArg(Message, Value, Callback));
        }
    }
}
